package com.dabao.exception;

import com.dabao.util.web.ResponseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminExceptionResolver implements HandlerExceptionResolver {

    private Logger logger = LoggerFactory.getLogger(AdminExceptionResolver.class);

    public ModelAndView resolveException(HttpServletRequest request,
                                         HttpServletResponse response, Object obj, Exception e) {
        String uri = request.getRequestURI();
        ModelAndView mv = new ModelAndView("/admin/error");
        logger.error(String.format("unexpected error has happend when request uri:%s to controller:%s", uri, obj.getClass().getName()), e);
        mv.addObject("error", ResponseUtils.error("服务器内部错误"));
        return mv;
    }

}
